package com.hunan.chinamobile.service.impl;

import com.hunan.chinamobile.dao.CityMapper;
import com.hunan.chinamobile.model.City;
import com.hunan.chinamobile.service.CityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class CityServiceImpl implements CityService{

    @Resource
    private CityMapper cityMapper;

    @Override
    public List<City> findByName(String name) {
        return cityMapper.findByName(name);
    }

    @Override
    public City check(String cityName) {
        return cityMapper.check(cityName);
    }

    @Override
    public void save(City model) {
        cityMapper.insert(model);
    }

    @Override
    public void deleteById(String id) {
        cityMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(City model) {
        cityMapper.updateByPrimaryKey(model);
    }

    @Override
    public City findById(String id) {
        return cityMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<City> findAll() {
        List<City> cs = cityMapper.selectAll();
        if(cs != null)
            cs.sort((a,b)->a.getCreatedAt().compareTo(b.getCreatedAt()));
        return cs;
    }
}
